Component({
    properties: {
        config: {
            type: Object,
            value: {}
        },
        preload: {
            type: Boolean,
            value: !1
        },
        hideLoading: {
            type: Boolean,
            value: !0
        }
    },
    ready: function() {
        var t, n = this;
        this.data.preload && (t = this.selectComponent("#poster"), this.downloadStatus = "doing", 
        t.downloadResource(this.config).then(function() {
            n.downloadStatus = "success", n.trigger("downloadSuccess");
        }).catch(function(t) {
            n.downloadStatus = "fail", n.trigger("downloadFail", t);
        }));
    },
    methods: {
        trigger: function(t, n) {
            this.listener && "function" == typeof this.listener[t] && this.listener[t](n);
        },
        once: function(t, n) {
            void 0 === this.listener && (this.listener = {}), this.listener[t] = n;
        },
        downloadResource: function(t, n) {
            var o = this;
            return new Promise(function(e, i) {
                t && (o.downloadStatus = null);
                var a = o.selectComponent("#poster");
                o.downloadStatus && "fail" !== o.downloadStatus ? "success" === o.downloadStatus ? e() : (o.once("downloadSuccess", function() {
                    return e();
                }), o.once("downloadFail", function(t) {
                    return i(t);
                })) : a.downloadResource(n).then(function() {
                    o.downloadStatus = "success", e();
                }).catch(function(t) {
                    return i(t);
                });
            });
        },
        onCreate: function() {
            var t = this, n = 0 < arguments.length && void 0 !== arguments[0] && arguments[0], o = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : {};
            return this.config = o, new Promise(function(e, i) {
                return t.data.hideLoading || wx.showLoading({
                    mask: !0,
                    title: "生成中"
                }), t.downloadResource("boolean" == typeof n && n, o).then(function() {
                    t.data.hideLoading || wx.hideLoading(), t.selectComponent("#poster").create(o).then(function(t) {
                        e(t);
                    }).catch(function(t) {
                        i(t);
                    });
                }).catch(function(n) {
                    t.data.hideLoading || wx.hideLoading(), i(n), console.error(n), t.triggerEvent("fail", n);
                });
            });
        },
        onCreateSuccess: function(t) {
            t = t.detail, this.triggerEvent("success", t);
        },
        onCreateFail: function(t) {
            console.error(t), this.triggerEvent("fail", t);
        }
    }
});